/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Consultar.java
 *
 * Created on 02/11/2011, 12:00:14
 */
package Interfaces;

import classes.Artigo;
import classes.EventoPrincipal;
import conexaoBD.mySQLcrud;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import classes.AreaTematica;
import classes.EventoPrincipal;
import classes.Palestrante;
import classes.Recurso;
import conexaoBD.mySQLconnection;
import conexaoBD.mySQLcrud;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ListModel;

/**
 *
 * @author Kazuo
 */
public class TelaCadastroWorkshop extends javax.swing.JFrame {

        private mySQLcrud connectionCrud;
    private ArrayList<EventoPrincipal> listaEventosPrincipal;
    private ArrayList<Recurso> listaRecursosSelecionados;
    private ArrayList<Palestrante> listaPalestranteSelecionados;
    ArrayList<AreaTematica> areaTema;
    Dimension s = new Dimension(59, 20);
    private ArrayList<Artigo> arrayArtigo = new ArrayList<Artigo>();
    
    /** Creates new form Consultar */
    public TelaCadastroWorkshop() {
        initComponents();

        //arrayEventoPrincipal = connectionCr
        connectionCrud = new mySQLcrud();
        cbEventoPrincipal.setPreferredSize(s);
        jDateInicio.setPreferredSize(s);
        jDateTermino.setPreferredSize(s);
        
        preencherComboBoxEventoPrincipal();
        
    }

    private void preencherComboBoxEventoPrincipal() {
        listaEventosPrincipal = connectionCrud.listaEventoPrincipal("");
        for (EventoPrincipal a : listaEventosPrincipal) {
            cbEventoPrincipal.addItem(a.getNomeEventoPrincipal());
        }
    }


    public void setListaRecursosSelecionados(ArrayList<Artigo> listaRecursosObj) {
        arrayArtigo = listaRecursosObj;
        DefaultListModel listaRecursosModel = new DefaultListModel();

        for (Artigo r : listaRecursosObj) {
            listaRecursosModel.addElement(r.getTituloArtigo());
        }
        listArtigos.setModel(listaRecursosModel);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        lblTitulo = new javax.swing.JLabel();
        lblParamConsulta = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblNome = new javax.swing.JLabel();
        txtNome = new javax.swing.JTextField();
        lblTemaPrincipal = new javax.swing.JLabel();
        txtTemaPrincipal = new javax.swing.JTextField();
        cbEventoPrincipal = new javax.swing.JComboBox();
        lblEventoPrincipal = new javax.swing.JLabel();
        btConfirmar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        lblDataInicio = new javax.swing.JLabel();
        lblDataTermino = new javax.swing.JLabel();
        btArtigos = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        listArtigos = new javax.swing.JList();
        jDateTermino = new com.toedter.calendar.JDateChooser();
        jDateInicio = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblTitulo.setFont(new java.awt.Font("Tahoma", 1, 14));
        lblTitulo.setText("Cadastro de");
        jPanel1.add(lblTitulo);

        lblParamConsulta.setFont(new java.awt.Font("Tahoma", 1, 16));
        lblParamConsulta.setText("Workshops");
        jPanel1.add(lblParamConsulta);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        lblNome.setText("Nome:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblNome, gridBagConstraints);

        txtNome.setToolTipText("Digite o nome do Workshop");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 153;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(txtNome, gridBagConstraints);

        lblTemaPrincipal.setText("Tema Principal:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblTemaPrincipal, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.ipadx = 153;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(txtTemaPrincipal, gridBagConstraints);

        cbEventoPrincipal.setToolTipText("Selecione o evento principal que se encontra o Workshop");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.ipadx = 103;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(cbEventoPrincipal, gridBagConstraints);

        lblEventoPrincipal.setText("Evento Principal:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblEventoPrincipal, gridBagConstraints);

        btConfirmar.setText("Confirmar");
        btConfirmar.setToolTipText("Confirmar Cadastro de Workshop");
        btConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btConfirmarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(30, 2, 30, 2);
        jPanel2.add(btConfirmar, gridBagConstraints);

        btCancelar.setText("Cancelar");
        btCancelar.setToolTipText("Cancelar e retornar para a tela anterior");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(16, 50, 16, 50);
        jPanel2.add(btCancelar, gridBagConstraints);

        lblDataInicio.setText("Data de Início:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblDataInicio, gridBagConstraints);

        lblDataTermino.setText("Data de Término:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(lblDataTermino, gridBagConstraints);

        btArtigos.setText("Adicionar Artigos");
        btArtigos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btArtigosActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(29, 0, 8, 0);
        jPanel2.add(btArtigos, gridBagConstraints);

        listArtigos.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { " ", " ", " ", " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listArtigos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(listArtigos);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 120;
        jPanel2.add(jScrollPane2, gridBagConstraints);

        jDateTermino.setPreferredSize(new java.awt.Dimension(56, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanel2.add(jDateTermino, gridBagConstraints);

        jDateInicio.setPreferredSize(new java.awt.Dimension(56, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 12;
        jPanel2.add(jDateInicio, gridBagConstraints);

        jLabel1.setText("jLabel1");
        jPanel2.add(jLabel1, new java.awt.GridBagConstraints());

        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("Atenção: Todos os campos são obrigatórios!");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(0, 41, 0, 0);
        jPanel2.add(jLabel2, gridBagConstraints);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(111, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btArtigosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btArtigosActionPerformed
        // TODO add your handling code here:
        TelaAdicionarArtigos t = new TelaAdicionarArtigos();
        t.setFormilario(this);
        t.setVisible(true);
    }//GEN-LAST:event_btArtigosActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btCancelarActionPerformed

    private void btConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConfirmarActionPerformed

        String nome = txtNome.getText();
        String eventoPrincipal = (String) cbEventoPrincipal.getSelectedItem();
        String temaPrincipal = txtTemaPrincipal.getText();
        String dataInicio = jDateInicio.getDate().toString();
        String dataTermino = jDateTermino.getDate().toString();
        String[] selectedValues = (String[]) listArtigos.getSelectedValues();
        EventoPrincipal ep = null;
        int codAgenda = -1;
        ArrayList<Artigo> tmpArt = new ArrayList<Artigo>();
        for (EventoPrincipal tmp : listaEventosPrincipal) {
            if (tmp.getNomeEventoPrincipal().equals(eventoPrincipal)) {
                ep = tmp;
                codAgenda = tmp.getCodAgenda();
            }
        }

        for (Artigo art : arrayArtigo) {
            for (String str : selectedValues) {
                if (art.getTituloArtigo().equals(str)) {
                    tmpArt.add(art);
                }
            }
        }
        //Chama o método do BD
    }//GEN-LAST:event_btConfirmarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TelaConsulta().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btArtigos;
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btConfirmar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cbEventoPrincipal;
    private com.toedter.calendar.JDateChooser jDateInicio;
    private com.toedter.calendar.JDateChooser jDateTermino;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblDataInicio;
    private javax.swing.JLabel lblDataTermino;
    private javax.swing.JLabel lblEventoPrincipal;
    private javax.swing.JLabel lblNome;
    private javax.swing.JLabel lblParamConsulta;
    private javax.swing.JLabel lblTemaPrincipal;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JList listArtigos;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtTemaPrincipal;
    // End of variables declaration//GEN-END:variables
}
